#include <stdio.h>
#include <stdint.h>
#include "retarget.h"
#include "lib/mem.h"
#include "cmsis_compiler.h"
#include "log/logger.h"

extern "C" 
{
__ASM (".global __use_no_semihosting");
//#pragma import(__use_no_semihosting_swi)
//#pragma import(__use_no_semihosting)

struct __FILE { int handle; /* Add whatever you need here */ };

FILE __stdout;
FILE __stdin;
FILE __stderr;

int fputc(int c, FILE *f) {  
  return -1;
}

// int fgetc(FILE *f) {
//   return (-1);
// }

int ferror(FILE *f) {
  /* Your implementation of ferror */
  return EOF;
}

void _ttywrch(int c) {
}

void _sys_exit(int return_code) {
label:  goto label;  /* endless loop */
}
}

//c++ 
void * operator new(size_t size)
{
    return MemMalloc(size);
}

void operator delete(void * ptr)
{
    return MemFree(ptr);
}

void *operator new[](size_t size) 
{
    return MemMalloc(size);
}

void operator delete[](void * ptr) 
{
    MemFree(ptr);
}
